
$(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function() {
		login();
    }
});

function login() {
	$.modal.loading($("#btnSubmit").data("loading"));
	var username = $("input[name='phoneNo']").val().trim();
    var password = $("input[name='password']").val().trim();
    $.ajax({
        type: "post",
        url: ctx + "sign",
        data: {
            "username": username,
            "password": password
        },
        success: function(r) {
            if (r.code == 200) {
            	layer.msg(r.msg,{
            		  icon: 1,
            		  time: 2000 //2秒关闭（如果不配置，默认是3秒）
            		}, function(){
            		location.href = ctx + 'login';
            		}); 
            } else {
            	$.modal.closeLoading();
            	$.modal.confirm(r.msg);
            }
        }
    });
}

function validateRule() {
    $("#signupForm").validate({
        rules: {
        	phoneNo: {
                required: true
            },
            password: {
                required: true,
                minlength: 6
            },
            conPassword:{
            	required: true,
            	equalTo: "#password"
            }
        },
        messages: {
        	phoneNo: {
                required: "请输入您的手机号",
            },
            password: {
                required: "请输入您的密码",
                minlength: "密码长度不能小于 6 个字母"
            },
            conPassword:{
            	required: "请再次输入密码",
            	equalTo: "两次密码输入不一致"
            }
        }
    })
}
